home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / BitBoard.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  124 lines

  1. /* BitBoard.c -- member functions of class BitBoard
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet: kgorlen@alw.nih.gov
  20.     January, 1986
  21.  
  22. Function:
  23.     
  24.  
  25. $Log:    BitBoard.c,v $
  26.  * Revision 3.0  90/05/20  00:19:09  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30.  
  31. #include "BitBoard.h"
  32. #include "nihclIO.h"
  33.  
  34. #define    THIS    BitBoard
  35. #define    BASE    Object
  36. #define BASE_CLASSES BASE::desc()
  37. #define MEMBER_CLASSES
  38. #define VIRTUAL_BASE_CLASSES Object::desc()
  39.  
  40. DEFINE_CLASS(BitBoard,1,"$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/BitBoard.c,v 3.0 90/05/20 00:19:09 kgorlen Rel $",BitBoard::init,NULL);
  41.  
  42. BitBoard squareBitBoard[64];
  43. BitBoard rankBitBoard[8];
  44. BitBoard fileBitBoard[8];
  45. unsigned char bit_count[256];
  46.  
  47. void BitBoard::init(const Class&)
  48. {
  49.     register BitBoard* p = squareBitBoard;
  50.     register unsigned i,j,k;
  51.     for (i=0; i<8; i++) {
  52.         for (j=0, k=1; j<8; j++, k+=k) {
  53.             (*p++).c[i] = k;
  54.         }
  55.     }
  56.     p = rankBitBoard;
  57.     register BitBoard* q = fileBitBoard;
  58.     for (i=0, k=1; i<8; i++, k+=k) {
  59.         (*p++).c[i] = 0xFF;
  60.         for (j=0; j<8; j++) {
  61.             (*q).c[j] = k;
  62.         }
  63.         q++;
  64.     }
  65. }
  66.  
  67. unsigned BitBoard::capacity() const { return sizeof(BitBoard)*8; }
  68.  
  69. void BitBoard::deepenShallowCopy()    {}
  70.  
  71. unsigned BitBoard::hash() const { return m[0]^m[1]; }
  72.     
  73. bool BitBoard::isEmpty() const { return m[0]==0 && m[1]==0; }
  74.     
  75. bool BitBoard::isEqual(const Object& ob) const
  76. {
  77.     return ob.isSpecies(classDesc) && *this==castdown(ob);
  78. }
  79.  
  80. const Class* BitBoard::species() const { return &classDesc; }
  81.  
  82. void BitBoard::printOn(ostream& strm) const
  83. {
  84.     for (register i=0; i<8; i++) {
  85.         strm << '\n';
  86.         for (register j=7; j>=0; j--) {
  87.             if (includes(8*i+j)) strm << " *";
  88.             else strm << " .";
  89.         }
  90.     }
  91. }        
  92.  
  93. unsigned BitBoard::size() const    { return count(); }
  94.  
  95. BitBoard::BitBoard(OIOin& strm)
  96.     : BASE(strm)
  97. {
  98.     strm >> m[0] >> m[1];
  99. }
  100.  
  101. void BitBoard::storer(OIOout& strm) const
  102. {
  103.     BASE::storer(strm);
  104.     strm << m[0] << m[1];
  105. }
  106.  
  107. BitBoard::BitBoard(OIOifd& fd)
  108.     : BASE(fd)
  109. {
  110.     fd.get((char*)c,8);
  111. }
  112.  
  113. void BitBoard::storer(OIOofd& fd) const
  114. {
  115.     BASE::storer(fd);
  116.     fd.put((char*)c,8);
  117. }
  118.  
  119. int BitBoard::compare(const Object&) const
  120. {
  121.     shouldNotImplement("compare");
  122.     return 0;
  123. }
  124.